home *** CD-ROM | disk | FTP | other *** search
- -- Hang onto your hats. Welcome to the monstrous keyDown hack.
- -- This ugly piece of coding wouldn't be necessary if text entry
- -- fields didn't use TextEdit and didn't require white backgrounds.
- -- Let's just hope you're smart enough to be using a fast machine.
-
- on keyDown
- global keyEditOK, fieldSpec
- -- if you're not supposed to be editing, then get the
- -- heck out of dodge
- if keyEditOK = FALSE then exit
-
- -- now set up the edit field so we know where to put the
- -- characters.
- case (the frameLabel) of
- "Create":
- put "FieldEntry" into theField
- put 10 into maxChars
- set validChars to "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_"
- set valid1stChars to "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
- end case
-
- -- process the keys themselves
- if the key = ENTER or the key = RETURN then
- if field theField <> "_" then
- -- Since the data field isn't empty, do something
- case (the frameLabel) of
- "Create":
- -- process the "OK" button
- doCreateOK
- end case
- end if
- else
- if the key = BACKSPACE then
- put the number of chars of field theField into numChars
- if numChars > 1 then
- if numChars > 2 then
- put char 1 to (numChars -2) of field theField & "_" into field theField
- else
- put "_" into field theField
- end if
- end if
- else
- put the number of chars of field theFIeld into numChars
- if numChars <= maxChars then
- if numChars = 1 then
- -- process first character
- if valid1stChars contains the key then
- put toupperC(the key) & "_" into field theField
- end if
- else
- -- process 2 through max chars
- if validChars contains the key then
- put char 1 to (numChars -1) of field theField¬
- & toupperC(the key) & "_" into field theField
- end if
- end if
- end if
- end if
- end if
- end keyDown
-
- on toupperC theChar
- if charToNum(theChar) >= 97 and charToNum(theChar) <= 122 then
- return numToChar(charToNum(theChar)-32)
- else
- return theChar
- end if
- end